/*
 * @Description: 全宗reducer
 * @Author: Rfan
 * @Date: 2022-01-08 16:30:05
 * @LastEditTime: 2022-05-19 14:42:42
 */

import { jsonClone } from '@/utils';
import { ADD_LEVEL_BY_ID, SET_ADD_TRANSFER_VISIBLE, SET_SELECT_KEYS } from '../constants';

export const LevelLayoutReducer = (state, action) => {
  switch (action.type) {
    /**
     * @description: 加载level表格数据及相关数据
     * @param {Array} data level列表
     * @param {Number} id 档案类型ID
     * @return {*}
     */
    case ADD_LEVEL_BY_ID: {
      return {
        ...state,
        levelList: action.data,
        tabList: [action.data[0]],
        currentAt: action.id
      };
    }
    case SET_SELECT_KEYS: {
      const { level, keys } = action;
      const levelStr = `${level}`;
      const levelKeys = jsonClone(state.levelSelectKeys);
      levelKeys[levelStr] = keys;

      console.log('keys reducer', { levelKeys, keys: action.keys });
      return {
        ...state,
        levelSelectKeys: levelKeys
      };
    }
    /**
     * @description: 设置移交弹窗展示状态
     * @param {boolean} visible level列表
     */
    case SET_ADD_TRANSFER_VISIBLE: {
      return {
        ...state,
        AddTransferVisible: action.visible
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
